package com.piggy.logi.sys.controller;

import com.piggy.common.core.domain.R;
import com.piggy.common.core.utils.poi.ExcelUtil;
import com.piggy.common.core.web.controller.BaseController;
import com.piggy.common.core.web.page.TableDataInfo;
import com.piggy.common.log.annotation.LogiLog;
import com.piggy.common.log.enums.BusinessType;
import com.piggy.common.satoken.annotation.Inner;
import com.piggy.logi.sys.api.bo.LogiPriceSegEditBo;
import com.piggy.logi.sys.api.bo.LogiPriceSegQueryBo;
import com.piggy.logi.sys.api.vo.LogiPriceSegExtVo;
import com.piggy.logi.sys.service.ILogiPriceSegService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

/**
 * 分段价格Controller
 *
 * @author piggy
 * @date 2023-08-14
 */
@Api(value = "分段价格控制器", tags = {"分段价格管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/logi/sys/seg")
public class InnerLogiPriceSegController extends BaseController {

    private final ILogiPriceSegService iLogiPriceSegService;

    /**
     * 查询分段价格列表
     */
    @Inner
    //@SaCheckPermission("sys:seg:list")
    @GetMapping("/inner/list")
    public TableDataInfo<LogiPriceSegExtVo> innerList(@Validated LogiPriceSegQueryBo bo) {
        return iLogiPriceSegService.queryPageList(bo);
    }

    /**
     * 获取分段价格详细信息
     */
    @Inner
    //@SaCheckPermission("sys:seg:query")
    @GetMapping("/inner/{id}")
    public R<LogiPriceSegExtVo> innerInfo(@NotNull(message = "主键不能为空")
                                        @PathVariable("id") Long id) {
        return R.ok(iLogiPriceSegService.queryById(id));
    }

    /**
     * 新增分段价格
     */
    @Inner
    //@SaCheckPermission("sys:seg:add")
    @PostMapping("inner/add")
    public R<LogiPriceSegExtVo> innerAdd(@Validated @RequestBody LogiPriceSegEditBo bo) {
        return R.ok(iLogiPriceSegService.insertByAddBo(bo));
    }

    /**
     * 修改分段价格
     */
    @Inner
    //@SaCheckPermission("sys:seg:edit")
    @PostMapping("inner/edit")
    public R<LogiPriceSegExtVo> innerEdit(@Validated @RequestBody LogiPriceSegEditBo bo) {
        return R.ok(iLogiPriceSegService.updateByEditBo(bo));
    }

    /**
     * 删除分段价格
     */
    @Inner
    //@SaCheckPermission("sys:seg:remove")
    @PostMapping("/inner/remove/{ids}")
    public R<Integer> innerRemove(@NotEmpty(message = "主键不能为空")
                             @PathVariable Long[] ids) {
        return R.ok(iLogiPriceSegService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }

}
